﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace NXBSaiGon
{
    public partial class Book : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void ProductsGrid_ItemCommand(object source, DataListCommandEventArgs e)
        {
            //
            if (e.CommandName == "datmua")
            {
                //lay id tu commandagrument
                Basket gio = (Basket)Session["GioHang"];

                Label lblten = (Label)e.Item.FindControl("lbl_ten");
                Image imgProduct = (Image)e.Item.FindControl("img_product");
                HiddenField txtCCao = (HiddenField)e.Item.FindControl("txtCCao");
                HiddenField txtCRong = (HiddenField)e.Item.FindControl("txtCRong");
                HiddenField txtBDay = (HiddenField)e.Item.FindControl("txtBDay");
                HiddenField txtKLuong = (HiddenField)e.Item.FindControl("txtKLuong");

                //HiddenField temp = (HiddenField)e.Item.FindControl("HiddenField1");
                
                string id = e.CommandArgument.ToString();
                string mota = "............";
                Label lblgia = (Label)e.Item.FindControl("lbl_gia");
                int soluong = 1;
                if (gio != null)
                {

                    //gio.Add(id,
                    //    lblten.Text, DateTime.Now, mota, imgProduct.ImageUrl, 0,
                    //    0,
                    //    0,
                    //    0, soluong, Convert.ToInt32(lblgia.Text));

                    gio.Add(id,
                        lblten.Text, DateTime.Now, mota, imgProduct.ImageUrl, Convert.ToInt32(txtCCao.Value),
                        Convert.ToInt32(txtCRong.Value),
                        Convert.ToInt32(txtBDay.Value),
                        Convert.ToInt32(txtKLuong.Value), soluong, Convert.ToInt32(lblgia.Text));
                }
                else
                {
                    Session["GioHang"] = new Basket();
                }
                Label_KetQuaGioHang.Text = lblten.Text + "da duoc add vao go hang";
                //Response.Write("<div class='added-item-alert'>" + lblten.Text + " have added to your ShoppingCart</div>");
            }
        }
    }
}